package com.shujia.userprofile.info.natural

import com.shujia.utils.{HBaseTools, SparkTool}
import org.apache.spark.sql.{DataFrame, Row, SparkSession}

object UserSexTag extends SparkTool {
  //  val tableName: String = "user_info"
  //  val columnFamily: String = "natural"
  //  val tagName: String = "sex"

  tableName = "user_info"
  columnFamily = "natural"
  tagName = "sex"

  override def extractData(spark: SparkSession): DataFrame = {

    import spark.implicits._
    import org.apache.spark.sql.functions._
    spark
      .table("dim.dim_pub_user_info_d_f").where($"pt" === pt)
      // 以用户id作为rk，提取用户性别最终写入HBase
      .select($"id".cast("String")
        , when($"sex" === "1", "男")
          .when($"sex" === "2", "女")
          .otherwise("未知") as "sex"
      )
  }

  //  override def saveDF(df: DataFrame): Unit = {
  //    HBaseTools.saveToHBase(df, tableName, columnFamily, tagName)
  //}
}
